import React, {useEffect, useState} from 'react';
import {View, Text, TouchableOpacity} from 'react-native';
import {List, Picker} from '@ant-design/react-native';
import {useNavigation} from '@react-navigation/native';
import AreaView from '../../components/Layout/AreaView';
import SearchHeadIcon from '../../components/SearchHeadIcon';
import styles from './style';
import {Icon, TextareaItem, InputItem} from '@ant-design/react-native';
import {getTeacher, sendInquiry} from '../../service/common';

const AskQuestuon = () => {
  const navigation = useNavigation();
  const [list, setList] = useState([]);
  useEffect(() => {
    navigation.setOptions({
      title: 'TB咨询',
    });
    getTeacher().then((res) => {
      if (res.code == 200) {
        const _list = res.data.map((item) => ({
          ...item,
          value: item.custId,
          label: item.custName,
        }));
        setList(_list);
      }
    });
  }, [navigation]);
  const [teacher, setTeacher] = useState();
  const [title, setTitle] = useState('');
  const [content, setContent] = useState('');
  return (
    <AreaView>
      <View style={styles.questiond_content}>
        <View style={styles.title_container}>
          <Text style={styles.title}>提问</Text>
        </View>
        <View style={styles.input_container}>
          <TextareaItem
            style={styles.textarea}
            rows={4}
            value={content}
            placeholder="请输入您的问题..."
            onChangeText={(val) => setContent(val)}
          />
          {/* <View style={styles.upload_container}>
            <View style={styles.upload}>
              <Icon name="file-image" />
              <Text style={styles.upload_text}>点击添加照片</Text>
            </View>
          </View> */}
        </View>
        <View style={styles.title_teach_container}>
          <InputItem
            style={styles.input_font}
            clear
            value={title}
            labelNumber={4}
            onChangeText={(val) => setTitle(val)}
            placeholder="请输入您的标题">
            <Text style={styles.input_text}>标题</Text>
          </InputItem>
          <Picker
            data={list}
            cols={1}
            value={teacher}
            onChange={(val) => setTeacher(val)}>
            <List.Item>
              <Text style={styles.list_text}>选择老师</Text>
            </List.Item>
          </Picker>
        </View>
        <View style={styles.btn_container}>
          <TouchableOpacity
            style={styles.btn}
            onPress={() => {
              console.log(title, content, teacher);
              if (title && content && teacher) {
                sendInquiry({
                  aswId: teacher[0],
                  content,
                  pic: '',
                  title,
                  topicid: '01',
                  type: '33c4d2f8dd7040be9a1a917e08770fcc',
                }).then(res => {
                  if (res.code * 1 === 200) {
                    navigation.goBack();
                  }
                });
              }
            }}>
            <Text style={styles.btn_text}>发送</Text>
          </TouchableOpacity>
        </View>
      </View>
    </AreaView>
  );
};

export default AskQuestuon;
